package com.hzhr.iot.user.controller;

import com.hzhr.iot.core.annotation.ApiImplicitInternalParams;
import com.hzhr.iot.core.annotation.Author;
import com.hzhr.iot.core.dto.ResponseExceptionDto;
import com.hzhr.iot.core.exception.ServiceException;
import com.hzhr.iot.user.controller.base.BaseController;
import com.hzhr.iot.user.model.user_moreCompleteRegistInfo.User_MoreCompleteRegistInfoGetModel;
import com.hzhr.iot.user.model.user_moreCompleteRegistInfo.User_MoreCompleteRegistInfoPutModel;
import com.hzhr.iot.user.service.User_MoreCompleteRegistInfoService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Map;

@Api(tags = "User_MoreCompleteRegistInfo", description = "用户的完善注册信息")
@RestController
@RequestMapping(value = "")
public class User_MoreCompleteRegistInfoController extends BaseController {
    @Autowired
    User_MoreCompleteRegistInfoService user_moreCompleteRegistInfoService;

    //region /users/{userId}/more-complete-regist-infos PUT
    //region swagger响应码 : putByUserId
    @ApiResponses({
            @ApiResponse(code = 200, message = "成功"),
    })
    //endregion
    //region swagger说明 : putByUserId
    @ApiOperation(value="用户完善注册信息", notes="用户完善注册信息  \n简介 : 更新用户信息；为用户分配角色；重新登录  \n步骤 :  \n1. 查询用户 : (√)  \n 根据路径参数userId查询用户(USER)user_1；  \n2. 判断用户状态 : (√)  \n 如果user_1.isNewUser为否，抛出异常201；  \n3. 验证公司 : (√)  \n 根据body.companyId查询公司company_1，如果company_1不存在，则抛出异常202；  \n4. 更新用户信息 : (√)  \n 根据body更新user_1的相关属性，同时设置以下属性：  \n (1) 将user_1.isNewUser设置为否；  \n (2) user_1.type的设置规则：如果user_1是company_1的创建人，将user_1.type设置为公司创始人，否则设置为公司用户；  \n (3) user_1.deptId的设置规则：如果user_1是company_1的创建人，查询company_1下“level=1的部门”(DEPT)dept_1，user_1.deptId = dept_1.id；  \n5. 为用户分配角色 :  \n 如果user_1是company_1的创建人：  \n 如果company_1.type为燃气公司，则在用户角色关系(USER_IN_ROLE)中添加user_1和“id=1的角色”的对应关系，  \n 如果company_1.type为物联网设备公司，则在用户角色关系(USER_IN_ROLE)中添加user_1和“id=3的角色”的对应关系，  \n 否则：  \n 在用户角色关系(USER_IN_ROLE)中添加user_1和“id=6的角色”的对应关系；  \n6. 提交以上事务  \n7. 登录 : (√)  \n 使用user_1.userName和user_1.password调用登录服务(login-service: /tokens GET)进行登录；  \n8. 返回信息 : (√)  \n 根据条件参数查询更新结果，组装响应并返回；  \n",produces = "application/json")
    //endregion
    //region swagger参数 : putByUserId
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌",required = true, dataType = "string", paramType = "header"),

            @ApiImplicitParam(name = "userId", value = "用户编号",required = true, dataType = "int", paramType = "path"),

            @ApiImplicitParam(name = "show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "show_info", value = "是否展示详情", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),

    })
    @ApiImplicitInternalParams({
            @ApiImplicitParam(name = "_token", value = "令牌",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-id", value = "用户编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-code", value = "用户代码",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-name", value = "用户名",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-company-id", value = "公司编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-dept-id", value = "部门编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-type", value = "用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE')",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-id", value = "交易流水号",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-type", value = "交易类型",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-access-mode", value = "访问模式 0:一般 1:全局",defaultValue = "0", required = false, dataType = "int", paramType = "header"),

            @ApiImplicitParam(name = "_show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "_show_info", value = "是否展示详情", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),

    })

    //endregion
    //region 请求 : putByUserId
    @RequestMapping(value = "/users/{userId}/more-complete-regist-infos", method = RequestMethod.PUT)
    //endregion
    @Author
    public ResponseEntity<User_MoreCompleteRegistInfoGetModel> putByUserId(@PathVariable("userId") Integer userId,
                                                                   @RequestParam @ApiIgnore Map<String, Object> query,
                                                                   @RequestBody User_MoreCompleteRegistInfoPutModel body) throws ServiceException {
        User_MoreCompleteRegistInfoGetModel responseBody = user_moreCompleteRegistInfoService.putByUserId(initHeader(), userId, query, body);
        return new ResponseEntity<>(responseBody, HttpStatus.OK);
        //endregion
    }
    //endregion
}
















































































































































































































































































































































































